load("/data1/home/zhoulab/lxw/Bcell/Bcell.filter.GCMat.RData")

ViewBatch <- function(all10x.Seurat,viewflag)
{
  #viewflag:1,key as patient; 2,key as patient_source
  #get all type
  AllBars <- rownames(all10x.Seurat@reductions$tsne@cell.embeddings)
  sourceType <- c()
  for(b in AllBars)
  {
    temp <- unlist(strsplit(b,"_"))

    if(viewflag == 1)
    {
      keys <- paste(temp[1],sep="_")
    }else
    {
      keys <- paste(temp[1],temp[2],sep="_")
    }
    sourceType <- c(sourceType,keys)
  }
  sourceType <- unique(sourceType)
  #get all type end!

  #draw pic
  picfile <- paste("BatchDis",viewflag,".png",sep ="")
  png(picfile,width=800,height=500)
  plot(all10x.Seurat@reductions$tsne@cell.embeddings,pch=".",col="grey",cex=0.2,main="view batch")
  AllCol <- distinctColorPalette(length(sourceType))
  for(i in seq(1,length(sourceType)))
  {
    ThisType <- sourceType[i]
    ThisCol <- AllCol[i]
    ThisBars <- grep(ThisType,AllBars)
    points(all10x.Seurat@reductions$tsne@cell.embeddings[ThisBars,],col=ThisCol,pch=".",cex=2)
  }
  dev.off()
  #draw pic end!

}

ViewBatch(Samples.integrated,2)
